package com.qitianyong.animator;

import android.app.Activity;
import android.graphics.drawable.AnimationDrawable;
import android.graphics.drawable.Drawable;
import android.widget.ImageView;

/**
 * Created by Administrator on 2016/10/9.
 */
public class CarAmimator {

    public static void startBufferAnimator(int imagesCount, String name, Activity activity, ImageView animView, int ms)
    {
        AnimationDrawable anim = new AnimationDrawable();
        for (int i = 1; i <= imagesCount; i++) {
            int id = activity.getResources().getIdentifier(name + i, "drawable", activity.getPackageName());
            Drawable drawable = activity.getResources().getDrawable(id);
            anim.addFrame(drawable, ms);
        }
        anim.setOneShot(false);
        animView.setImageDrawable(anim);
        anim.start();
    }

    public static void stopBufferAnimator(ImageView animView)
    {
        AnimationDrawable animationDrawable = (AnimationDrawable) animView.getDrawable();
        animationDrawable.stop();
    }
}
